/**
 * @file categories/dp/monotonous_queue/cf372c/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/3 21:19:20
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 150000 + 10;
const int M = 300 + 10;
ll f[2][N];
ll a[M], b[M], t[M];
int n, m, d;
int que[N];
int fl = 1;

void init() {
  memset(f, 207, sizeof(f));
  memset(que, 0, sizeof(que));
  for (int i = 1; i <= n; ++i) f[0][i] = 0;
  fl = 1;
}
void dp() {
  init();
  for (int i = 1; i <= m; ++i) {
    int l = 1, r = 0, k = 1;
    for (int j = 1; j <= n; ++j) {
      for (; k <= min(1LL * n, j + d * (t[i] - t[i - 1])); k++) {
        while (l <= r && f[fl ^ 1][que[r]] <= f[fl ^ 1][k]) r--;
        que[++r] = k;
      }
      while (l <= r && que[l] < max(1LL, j - d * (t[i] - t[i - 1]))) l++;
      f[fl][j] = f[fl ^ 1][que[l]] - abs(a[i] - j) + b[i];
    }
    fl ^= 1;
  }
}
int main() {
  // High rating and good luck!
  cin >> n >> m >> d;
  for (int i = 1; i <= m; ++i) cin >> a[i] >> b[i] >> t[i];

  dp();
  ll ans = -1e18;
  for (int i = 1; i <= n; ++i) ans = max(ans, f[fl ^ 1][i]);
  cout << ans << endl;
  return 0;
}
